﻿@using System.Collections
@using Projectmanagement.Entity
@using ProjectManagement.Models
@model IQueryable<Project>
@{
    ViewBag.Title = "Task";
    string type = ViewBag.type;
    //int id1 = Request.Params["pid1"] == null ? Model.First().ID : int.Parse(Request.Params["pid1"]);
    //int id2 = Request.Params["pid2"] == null ? Model.First().ID : int.Parse(Request.Params["pid2"]);
    //int id3 = Request.Params["pid3"] == null ? Model.First().ID : int.Parse(Request.Params["pid3"]);
    //int id4 = Request.Params["pid4"] == null ? Model.First().ID : int.Parse(Request.Params["pid4"]);
    //int id5 = Request.Params["pid5"] == null ? Model.First().ID : int.Parse(Request.Params["pid5"]);
}
@Html.Hidden("jibie", Employee.CurrentRoleLVL)
@Html.Hidden("hidProject")
@Html.Hidden("hidMember")
@Html.Hidden("hidTaskName")
<style type="text/css">
    #TabStrip{margin-top:9px;}
</style>
@{ Html.Telerik().TabStrip().Name("TabStrip").Items(tabstrip =>
   {
      
           tabstrip.Add().Text("待确认任务")
            .Content(@<text>
    @TaskNeedComfirm()
    </text>);
      

       tabstrip.Add().Text("过期任务")
           .Content(@<text>
    @RenderGrid1()
    </text>);
       tabstrip.Add().Text("我的任务").Content(@<text>
    @RenderGrid2()
    </text>);
       if (Employee.CurrentRoleLVL == RoleLevel.Manager)
       {
           tabstrip.Add().Text("下属任务").Content(@<text>
    @RenderGrid3()
    </text>);
       }


      
           tabstrip.Add().Text("已完成任务").Content(@<text>
    @TaskPassed()
    </text>);
     

       tabstrip.Add().Text("知会任务").Content(@<text>
    @TaskNotify()
    </text>);

   }).SelectedIndex(0).Render();}

@helper TaskNotify()
{
    @(Html.Telerik().Grid<_Task>()
                                .Name("TaskNotify").HtmlAttributes(new { @class = "taskindex" })
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ClientEvents(events => events.OnEdit("onEdit")
                .OnDataBinding("Grid_onDataBinding")
            //        .OnLoad("Grid_onLoad")
        )

    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("_SelectNotifyTaskIndex", "Task")
            .Insert("_InsertAjaxEditing", "Task");
    })
    .Columns(columns =>
    {
        columns.Bound(item => item.Ttype).Hidden();
        columns.Bound(item => item.ProjectCode);
        columns.Bound(item => item.TaskCode);
        columns.Bound(item => item.Owners).Width(140);
        columns.Bound(item => item.Name).Width(240);
        columns.Bound(item => item.StartDate).Width(100);
        columns.Bound(item => item.EndDate).Width(100);
        columns.Bound(item => item.Duration).Width(100);
        columns.Bound(item => item.TaskStateName).Width(100);
        //columns.Bound(item => item.Complement).Width(120);
        columns.Bound(item => item.Assinger).Width(100);
        columns.Bound(c => c.ID)
            .ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>")
            //.ClientTemplate("　 <a href='task/operation/<#= ID #>'>操作</a>")
                .Title("操作").Width(100);
    })
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
    .Scrollable(c => c.Height("353px"))
    .Sortable()
    .Resizable(resizing => resizing.Columns(true))
      )
}
@helper TaskPassed()
{
    @(Html.Telerik().Grid<_Task>()
                        .Name("PassedTask").HtmlAttributes(new { @class = "taskindex" })
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ClientEvents(events => events.OnEdit("onEdit")
                .OnDataBinding("Grid_onDataBinding")
            //        .OnLoad("Grid_onLoad")
        )
    .ToolBar(toolBar => toolBar.Template(
                                    @<text>
    <table>
        <tr>
            <td style="width: 400px">
                @Html.Partial("_ProjectMemberFilter")
            </td>
            <td>
                <label>
                    任务名称：</label>
                <input type="text" name="t-taskname" class="t-taskname" style="width: 150px" />
                <a class="t-button t-search" name="taskNameSearch">查询</a>
            </td>
        </tr>
    </table>
    </text>
                                    ))
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("_SelectPassedTaskIndex", "Task")
            .Insert("_InsertAjaxEditing", "Task");
    })
    .Columns(columns =>
    {
        columns.Bound(item => item.Ttype).Hidden();
        columns.Bound(item => item.ProjectCode);
        columns.Bound(item => item.TaskCode);
        columns.Bound(item => item.Owners).Width(140); ;
        columns.Bound(item => item.Name).Width(240);
        columns.Bound(item => item.StartDate).Width(100);
        columns.Bound(item => item.EndDate).Width(100);
        columns.Bound(item => item.Duration).Width(100);
        columns.Bound(item => item.TaskStateName).Width(100);
        //columns.Bound(item => item.Complement).Width(120);
        columns.Bound(item => item.Assinger).Width(100);
        columns.Bound(c => c.ID)
            .ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>")
            //.ClientTemplate("　 <a href='task/operation/<#= ID #>'>操作</a>")
                .Title("操作").Width(100);
    })
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
    .Scrollable(c => c.Height("353px"))
    .Sortable()
    .Resizable(resizing => resizing.Columns(true))
      )
}
@helper TaskNeedComfirm()
{
    @(Html.Telerik().Grid<_Task>()
                .Name("TaskNeedComfirm").HtmlAttributes(new { @class = "taskindex" })
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ClientEvents(events => events.OnEdit("onEdit")
                .OnDataBinding("Grid_onDataBinding")
            //        .OnLoad("Grid_onLoad")
        )
    .ToolBar(toolBar => toolBar.Template(
                                    @<text>
    <table>
        <tr>
            <td style="width: 400px">
                @Html.Partial("_ProjectMemberFilter")
            </td>
            <td>
                <label>
                    任务名称：</label>
                <input type="text" name="t-taskname" class="t-taskname" style="width: 150px" />
                <a class="t-button t-search" name="taskNameSearch">查询</a>
            </td>
        </tr>
    </table>
    </text>
                                    ))
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("_SelectTaskNeedConfirmIndex", "Task")
            .Insert("_InsertAjaxEditing", "Task");
    })
    .Columns(columns =>
    {
        columns.Bound(item => item.Ttype).Hidden();
        columns.Bound(item => item.ProjectCode).Width(140);
        columns.Bound(item => item.TaskCode);
        columns.Bound(item => item.Owners).Width(140);
        columns.Bound(item => item.Name).Width(240);
        columns.Bound(item => item.StartDate).Width(100);
        columns.Bound(item => item.EndDate).Width(100);
        columns.Bound(item => item.Duration).Width(100);
        columns.Bound(item => item.TaskStateName).Width(100);
        //columns.Bound(item => item.Complement).Width(120);
        columns.Bound(item => item.Assinger).Width(100);
        columns.Bound(c => c.ID)
            .ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>")
            //.ClientTemplate("　 <a href='task/operation/<#= ID #>'>操作</a>")
                .Title("操作").Width(100);
    })
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
    .Scrollable(c => c.Height("353px"))
    .Sortable()
    .Resizable(resizing => resizing.Columns(true))
      )
}
@helper RenderGrid1()
{
   
    @(Html.Telerik().Grid<_Task>()
        .Name("OverdueTask").HtmlAttributes(new { @class = "taskindex" })
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ClientEvents(events => events.OnEdit("onEdit")
        
                .OnDataBinding("Grid_onDataBinding")
            //    .OnLoad("Grid3_onLoad")
            )
    .ToolBar(toolBar => toolBar.Template(
                                    @<text>
    <table>
        <tr>
            <td style="width: 400px">
                @Html.Partial("_ProjectMemberFilter")
            </td>
            <td>
                <label>
                    任务名称：</label>
                <input type="text" name="t-taskname" class="t-taskname" style="width: 150px" />
                <a class="t-button t-search" name="taskNameSearch">查询</a>
            </td>
        </tr>
    </table>
    </text>
                                                                                         ))
                                                         .DataBinding(dataBinding =>
                                                         {
                                                             dataBinding.Ajax()
                                                                 .Select("_SelectOverdueTaskIndex", "Task")
                                                                 .Insert("_InsertAjaxEditing", "Task");
                                                         })
                                                         .Columns(columns =>
                                                         {
                                                             columns.Bound(item => item.Ttype).Hidden();
                                                             columns.Bound(item => item.ProjectCode);
                                                             columns.Bound(item => item.TaskCode);
                                                             columns.Bound(item => item.Name).Width(240);
                                                             columns.Bound(item => item.StartDate).Width(140);
                                                             columns.Bound(item => item.EndDate).Width(140);
                                                             columns.Bound(item => item.Duration).Width(120);
                                                             columns.Bound(item => item.Owners).Width(140);
                                                             //columns.Bound(item => item.Complement).Width(120);
                                                             columns.Bound(item => item.Assinger).Width(120);
                                                             columns.Bound(c => c.ID)
                                                                     .ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>")
                                                                     .Title("操作").Width(100);
                                                         })
                                                         .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                                         .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
                                                         .Scrollable(c => c.Height("353px"))
                                                         .Sortable()
                                                         .Resizable(resizing => resizing.Columns(true))
                                                           )
    
}
@helper RenderGrid2()
{
      
    @(Html.Telerik().Grid<_Task>()
        .Name("MyTask").HtmlAttributes(new { @class = "taskindex" })
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ClientEvents(events => events.OnEdit("onEdit")
                .OnDataBinding("Grid_onDataBinding")
            //        .OnLoad("Grid_onLoad")
        )
    .ToolBar(toolBar => toolBar.Template(
                                    @<text>
    <table>
        <tr>
            <td style="width: 400px">
                @Html.Partial("_ProjectMemberFilter")
            </td>
            <td>
                <label>
                    任务名称：</label>
                <input type="text" name="t-taskname" class="t-taskname" style="width: 150px" />
                <a class="t-button t-search" name="taskNameSearch">查询</a>
            </td>
        </tr>
    </table>
    </text>
                                    ))
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("_SelectMyTaskIndex", "Task")
            .Insert("_InsertAjaxEditing", "Task");
    })
    .Columns(columns =>
    {
        columns.Bound(item => item.Ttype).Hidden();
        columns.Bound(item => item.ProjectCode);
        columns.Bound(item => item.TaskCode);
        columns.Bound(item => item.Name).Width(240);
        columns.Bound(item => item.StartDate).Width(100);
        columns.Bound(item => item.EndDate).Width(100);
        columns.Bound(item => item.Duration).Width(100);
        columns.Bound(item => item.TaskStateName).Width(100);
        //columns.Bound(item => item.Complement).Width(120);
        columns.Bound(item => item.Assinger).Width(100);
        columns.Bound(c => c.ID)
           .ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>")
            //.ClientTemplate("　 <a href='task/operation/<#= ID #>'>操作</a>")
                .Title("操作").Width(100);
    })
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
    .Scrollable(c => c.Height("353px"))
    .Sortable()
    .Resizable(resizing => resizing.Columns(true))
      )

}
@helper RenderGrid3()
{
    if (Employee.CurrentRoleLVL >= 100)
    {
    
    @(Html.Telerik().Grid<_Task>()
            .Name("SubordinateTask").HtmlAttributes(new { @class = "taskindex" })
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ClientEvents(events => events.OnEdit("onEdit")
                .OnDataBinding("Grid_onDataBinding")
        //            .OnLoad("Grid1_onLoad")
                    )
    .ToolBar(toolBar => toolBar.Template(
                                    @<text>
    <table>
        <tr>
            <td style="width: 400px">
                @Html.Partial("_ProjectMemberFilter")
            </td>
            <td style="width: 350px">
                <label>
                    任务名称：</label>
                <input type="text" name="t-taskname" class="t-taskname" style="width: 150px" />
                <a class="t-button t-search" name="taskNameSearch">查询</a>
            </td>
            <td align="left">
                <a class="t-button t-grid-add" href="/Project?Project-mode=insert">新增记录</a>
            </td>
        </tr>
    </table>
    </text>
                                    ))
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("_SelectSubordinateTaskIndex", "Task")
            .Insert("_InsertAjaxEditing", "Task");
    })
    .Columns(columns =>
    {
        columns.Bound(item => item.Ttype).Hidden();
        columns.Bound(item => item.ProjectID).Hidden();
       
        columns.Bound(item => item.Name).Width(240);
        columns.Bound(item => item.TaskCode).Width(150);
        columns.Bound(item => item.StartDate).Width(100);
        columns.Bound(item => item.EndDate).Width(100);
        columns.Bound(item => item.Duration).Width(60);
        columns.Bound(item => item.TaskStateName).Width(100);
        columns.Bound(item => item.Owners).Width(100);
        //columns.Bound(item => item.Complement).Width(120);
        columns.Bound(item => item.Assinger).Width(100);
        columns.Bound(c => c.ID)
                .ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>")
                .Title("操作").Width(100);
    })
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
    .Scrollable(c => c.Height("353px"))
    .Sortable()
    .Resizable(resizing => resizing.Columns(true))
      )
  
    }
}
@helper RenderGrid4()
{
   
    @(Html.Telerik().Grid<_Task>()
            .Name("WarningTask").HtmlAttributes(new { @class = "taskindex" })
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ClientEvents(events => events.OnEdit("onEdit")
                .OnDataBinding("Grid_onDataBinding")
            //        .OnLoad("Grid2_onLoad")
                )
    .ToolBar(toolBar => toolBar.Template(
                                    @<text>
    <table>
        <tr>
            <td style="width: 400px">
                @Html.Partial("_ProjectMemberFilter")
            </td>
            <td>
                <input type="text" name="t-taskname" class="t-taskname" style="width: 150px" />
            </td>
            <td align="left">
                <a class="t-button t-search" name="taskNameSearch">查询</a>
            </td>
        </tr>
    </table>
    </text>
                                    ))
    .DataBinding(dataBinding =>
    {
        dataBinding.Ajax()
            .Select("_SelectWarningTaskIndex", "Task")
            .Insert("_InsertAjaxEditing", "Task");
    })
    .Columns(columns =>
    {
        columns.Bound(item => item.Ttype).Hidden();
        columns.Bound(item => item.ProjectCode);
        columns.Bound(item => item.TaskCode);
        columns.Bound(item => item.Name).Width(240);
        columns.Bound(item => item.StartDate).Width(100);
        columns.Bound(item => item.EndDate).Width(100);
        columns.Bound(item => item.Duration).Width(100);
        columns.Bound(item => item.Owners).Width(100);
        //columns.Bound(item => item.Complement).Width(120);
        columns.Bound(item => item.Assinger).Width(100);
        columns.Bound(c => c.ID)
                .ClientTemplate("<a class='t-button' onclick='showtask(<#= ID #>)'>操作</a>")
                .Title("操作").Width(100);
    })
    .Editable(editing => editing.Mode(GridEditMode.PopUp))

    .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
    .Scrollable(c => c.Height("353px"))
    .Sortable()
    .Resizable(resizing => resizing.Columns(true))
      )

}
@(Html.Telerik().Window()
    .Name("ChangeState")
    .Visible(false)
    .Title("变更状态")
    .Modal(true)
    .Width(500)
    .Draggable(true)
    .Height(400)
    .Content(@<text>
<div id="ChangeState-details">
    <input type="hidden" name="tid" />
    <table class="noline" style="width: 100%;">
        <tr>
            <td style="width: 100px;">任务名称
            </td>
            <td class="taskname"></td>
        </tr>
        <tr>
            <td style="width: 100px;">任务执行人
            </td>
            <td class="taskowners"></td>
        </tr>
        <tr>
            <td style="width: 100px;">任务说明
            </td>
            <td class="taskcontent"></td>
        </tr>
        <tr>
            <td style="width: 100px;">知识库链接
            </td>
            <td class="taskKMLinks"></td>
        </tr>
        <tr>
            <td style="width: 100px;">可交付成果
            </td>
            <td class="taskDeliverables"></td>
        </tr>
        <tr>
            <td style="width: 100px;">状态选择
            </td>
            <td>
                <select name="sid" onchange="changestate(this)">
                </select>
                <select name="toname">
                </select>
            </td>
        </tr>
        <tr>
            <td>说明
            </td>
            <td>
                <textarea style="width: 100%; height: 100px;" name="des"></textarea>
            </td>
        </tr>
    </table>
    <div style="text-align: right;">
        <a class="t-button" onclick="submitchangestate()">确定</a>
    </div>
</div>
</text>)
      )
<script type="text/javascript">

    function GridNotTask_onDataBinding(e) {
        var state = $("#ddlNotTaskState").val();
        e.data = {
            state: state
        };
    }

    function Grid_onDataBinding(e) {
        var conferenceid = $("#hidProject").val();
        var member = $("#hidMember").val();
        var taskName = $("#hidTaskName").val();
        if (member == "-请选择-") {
            member = "";
        }
        e.data = {
            conferenceid: conferenceid,
            member: member,
            taskName: taskName
        };
    }

    function showtask(id) {
        $.post('Task/GetDetail/', { taskid: id }, function (result) {
            $('.TastMessageT-wrapper').html(result);
            var window = $('#TastMessageT').data('tWindow');
            window.center().open();
        });
    }

    function getNotTaskState() {
        var selec = "0";
        var url = "/TimeLine/GetTaskState/";
        $("#ddlNotTaskState").find("option").remove();
        $.getJSON(url, { 'id': selec }, function (data) {
            $.each(data, function (i, item) {
                $("<option></option>").val(item["ID"]).text(item["Name"]).appendTo($("#ddlNotTaskState"));
            });
        });
    }
    $(document).ready(function () {
        getNotTaskState();
        initialProjectMemberfilter();

        $(".projectfilter").change(function () {
            $("#hidProject").val($(this).closest(".projectfilter").val());
            $(this).closest(".taskindex").data("tGrid").ajaxRequest();
        });

        $(".memberfilter").change(function () {
            var memberValue = $(this).closest(".memberfilter").find("option:selected")[0].text;
            $("#hidMember").val(memberValue);
            $(this).closest(".taskindex").data("tGrid").ajaxRequest();
        });
        $("#btnSearch").click(function () {
            $("#TaskNotProgress").data("tGrid").ajaxRequest();
        });

        $(".t-search").click(function () {
            $("#hidProject").val($(this).parents().find(".projectfilter").val());
            $("#hidMember").val($(this).parents().parents().find(".memberfilter").val());
            $("#hidTaskName").val($(this).parents().parents().find(".t-taskname").val());
            $(this).closest(".taskindex").data("tGrid").ajaxRequest();
        });
    });
    function onEdit(e) {
        var taskId = e.dataItem["ID"];
        if (taskId == 0) {
            $("input[name=Owners]").hide();
            $("input[name=Owners]").after($("input[name=Owners]").val());
            $("#comment").hide();
        } else {
            $("#legendTitle").html("编辑任务");
            $("input[name=Owners]").hide();
            $("input[name=Owners]").after($("input[name=Owners]").val());
            $("#Name").attr("disabled", "disabled");
            $("#TaskStateID").attr("disabled", "disabled");
            $("select[name=ProjectID]").hide();
            $("select[name=ProjectID]").after($("select[name=ProjectID] option:selected").text());
            $.post('/Task/GetCommentList', { taskid: taskId }, function (result) {
                $('#commentList').html(result);
            });
        }
    }
    function dtonChange(e) {
        $("form").submit();
    }
</script>
@(Html.Telerik().Window().Title("任务信息")
    .Name("TastMessageT")
    .Content(@<text><div class="dialogue-TastMessageT">
        <div class="TastMessageT-wrapper">
        </div>
    </div></text>)
    .Width(1050)
    .Height(550)
    .Modal(true).Visible(false).Draggable(true)
)